#include "StdAfx.h"
#include "player.h"


player::player()
{
	HBar.x = 0;
	HBar.y = 0;
	HBar.h = 20;
	EBar.x = 0;
	EBar.y = 25;
	EBar.h = 20;
	EBar.w = 0;
	xVel = 0.0;
	yVel = 0.0;
	x = 0.0;
	y = 0.0;
	box.x = 100;
	box.y = 150;
	box.w = 50;
	box.h = 50;
	range.x = box.x - 25;
	range.y = box.y - 25;
	range.w = box.w + 50;
	range.h = box.h + 50;
	xp = 0;
	level = 1;
	maxXp = level * 55;
	strength = level * 5 + 30;
	dextarity = level * 1.25f + 25;
	damage = strength * .46f;	
	maxHealth = strength * 1.35f;
	health = maxHealth;
	crit = dextarity * .40f;
	dodgeChance = dextarity * .40f;
	armor = level * 1.8f + 15;	
	swingDelay = false;
	hpot = 0;
	HBar.w = health*2;
}
player::~player()
{
}
void player::move(int deltaTicks)
{
	x += xVel * deltaTicks / 1000.f;
	y += yVel * deltaTicks / 1000.f;
	box.x = x;
	box.y = y;
	range.x = box.x - 25;
	range.y = box.y - 25;
}

void player::playerDamage(monster *mob, hitQueue *log, TTF_Font *font, SDL_Color textColor)
{
	float trueDamage;
	
	trueDamage = damage - (mob -> armor * .25f);
	//crit chance
	int num = rand()%100+1;
	if(num >= 0 && num <= crit)
	{
		trueDamage = trueDamage * 2;
		log->setMessage("Critical!", mob->x, mob->y-15, trueDamage, font, textColor);
	}
	//dodge chance
	int dodge = rand()%100+1;
	if(dodge >= 0 && dodge <= mob ->dodgeChance)
	{
		trueDamage = 0;
		log->setMessage("Dodge!",mob->x,mob->y-15, font, textColor);
	}
	else if(!(num >= 0 && num <= crit))
		log->setMessage("Hit!", mob->x, mob->y-15, trueDamage, font, textColor);
	mob -> health -= trueDamage;// mob health - playor damage
	if(mob -> health <=0)
	{
		mob -> alive = false;
		xp += 30;
			
	}
	trueDamage = 0;
}
void player::lvlUp(TTF_Font *font, SDL_Color textColor)
{
	if(xp  >= maxXp)
	{
		level += 1;
		xp = 0;
		maxXp = level * 55;
		strength = level * 5 + 35;
		dextarity = level * 1.25f + 25;
		damage = strength * .44f;	
		maxHealth = strength * 1.35f;
		health = maxHealth;
		crit = dextarity * .40f;
		dodgeChance = dextarity * .40f;
		armor = level * 1.8f + 18;
		levelQ.setMessage("Level: ", 0, 50, level, font, textColor);
	}
}

void player::updateBars()
{
	int maxPixels = 400;
	float pixels = maxPixels / maxHealth;
	float epixels = maxPixels / maxXp;
	HBar.w = health * pixels;
	EBar.w = xp * epixels;
	
}
